/**
 * ...
 * @author Franco Ponticelli
 */

package uform.ui.comp;
import uform.property.Property;
import uform.ui.comp.Component;
import uform.property.IProperty;
import uform.property.INiladicProperty;
import uform.property.NiladicProperty;
import uform.ui.comp.NamedComponent;

class Trigger extends NamedComponent
{
	public var text(default, null) : IProperty<String>;
	public var handler(default, null) : INiladicProperty;
	public var kind(default, null) : TriggerKind;
	public function new(name : String, text : String, ?kind : TriggerKind, handler : Void -> Void)
	{
		super(name);
		this.text = new Property(text);
		this.handler = new NiladicProperty();
		this.handler.set(handler);
		this.kind = null == kind ? TriggerKind.Action : kind;
	}
	
	override function dispose()
	{
		text.onChange.clear();
		text = null;
		handler.onChange.clear();
		handler = null;
		super.dispose();
	}
	
	public function trigger()
	{
		handler.execute();
	}
}